<?php
/**
 * 广告位
 *
 * User: kaikaic
 * Date: 2018/4/20
 * Time: 15:22
 */

namespace app\admin\service;

use service\BasicService;
use think\Db;

class AdvService extends BasicService {

    public function init() {
        $this->dataTable = ['SystemAdvSpot', 'SystemAdv'];
    }

    /**
     * 全部广告位
     */
    public function listAdvs() {
        $records = Db::name($this->dataTable[0])->select();

        $dataList = array();
        for ($i=0; $i<count($records); $i++) {
            $dataList[$records[$i]['id']] = $records[$i]['name'];
        }

        return $dataList;
    }

    /**
     * 列出广告位下的广告
     */
    public function listAdvBySpot($id) {
        return Db::name($this->dataTable[1])->where('spot_id', $id)->select();
    }

    /**
     * 读取广告信息
     */
    public function findAd($id) {
        return Db::name($this->dataTable[1])->where('id', $id)->find();
    }


}

